#include "LandData.h"
#define LAND_SPAN 30
LandData::LandData(int width, int height) {//构造函数
    int rows = height - 1;
    int cols = width - 1;
    int gzCount = rows * cols;
    vCount = gzCount * 2 * 3;
    vData = new float[vCount * 7];
    float sSpan = 32.0f / cols;
    float tSpan = 32.0f / rows;
    float xStart = -LAND_SPAN * cols / 2.0f;
    float zStart = -LAND_SPAN * rows / 2.0f;
    float ssSpan = 1.0f / cols;//计算山地高度的纹理S 坐标跨度
    float ttSpan = 1.0f / rows;//计算山地高度的纹理T 坐标跨度
    int indexTemp = 0;//辅助索引
    for (int i = 0; i < cols; i++) {//遍历地形网格所有列
        for (int j = 0; j < rows; j++) {//遍历地形网格所有行
            float x0 = xStart + LAND_SPAN * i;//当前网格0 号顶点X 坐标
            float y0 = 0;//当前网格0 号顶点Y 坐标
            float z0 = zStart + LAND_SPAN * j;//当前网格0 号顶点Z 坐标
            float s0 = sSpan * i;//当前网格0 号顶点纹理S 坐标(外观)
            float t0 = tSpan * j;//当前网格0 号顶点纹理T 坐标(外观)
            float ss0 = ssSpan * i;//当前网格0 号顶点纹理S 坐标(高度)
            float tt0 = ttSpan * j;//当前网格0 号顶点纹理T 坐标(高度)
            float x1 = xStart + LAND_SPAN * (i + 1);
            float y1 = 0;
            float z1 = zStart + LAND_SPAN * j;
            float s1 = sSpan * (i + 1);
            float t1 = tSpan * j;
            float ss1 = ssSpan * (i + 1);
            float tt1 = ttSpan * j;
            float x2 = xStart + LAND_SPAN * i;
            float y2 = 0;
            float z2 = zStart + LAND_SPAN * (j + 1);
            float s2 = sSpan * i;
            float t2 = tSpan * (j + 1);
            float ss2 = ssSpan * i;
            float tt2 = ttSpan * (j + 1);
            float x3 = xStart + LAND_SPAN * (i + 1);
            float y3 = 0;
            float z3 = zStart + LAND_SPAN * (j + 1);
            float s3 = sSpan * (i + 1);
            float t3 = tSpan * (j + 1);
            float ss3 = ssSpan * (i + 1);
            float tt3 = ttSpan * (j + 1);
            vData[indexTemp++] = x0;//将0 号顶点X 坐标存入结果数组
            vData[indexTemp++] = y0;//将0 号顶点Y 坐标存入结果数组
            vData[indexTemp++] = z0;//将0 号顶点Z 坐标存入结果数组
            vData[indexTemp++] = s0;//将0 号顶点S 纹理坐标存入结果数组(外观)
            vData[indexTemp++] = t0;//将0 号顶点T 纹理坐标存入结果数组(外观)
            vData[indexTemp++] = ss0;//将0 号顶点S 纹理坐标存入结果数组(高度)
            vData[indexTemp++] = tt0;//将0 号顶点T 纹理坐标存入结果数组(高度)
            vData[indexTemp++] = x3;
            vData[indexTemp++] = y3;
            vData[indexTemp++] = z3;
            vData[indexTemp++] = s3;
            vData[indexTemp++] = t3;
            vData[indexTemp++] = ss3;
            vData[indexTemp++] = tt3;
            vData[indexTemp++] = x1;
            vData[indexTemp++] = y1;
            vData[indexTemp++] = z1;
            vData[indexTemp++] = s1;
            vData[indexTemp++] = t1;
            vData[indexTemp++] = ss1;
            vData[indexTemp++] = tt1;
            vData[indexTemp++] = x0;
            vData[indexTemp++] = y0;
            vData[indexTemp++] = z0;
            vData[indexTemp++] = s0;
            vData[indexTemp++] = t0;
            vData[indexTemp++] = ss0;
            vData[indexTemp++] = tt0;
            vData[indexTemp++] = x2;
            vData[indexTemp++] = y2;
            vData[indexTemp++] = z2;
            vData[indexTemp++] = s2;
            vData[indexTemp++] = t2;
            vData[indexTemp++] = ss2;
            vData[indexTemp++] = tt2;
            vData[indexTemp++] = x3;
            vData[indexTemp++] = y3;
            vData[indexTemp++] = z3;
            vData[indexTemp++] = s3;
            vData[indexTemp++] = t3;
            vData[indexTemp++] = ss3;
            vData[indexTemp++] = tt3;
        }
    }
}
